package academic.concordia.bankofquebec.managedbean;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import academic.concordia.bankofquebec.entity.GIC;
import academic.concordia.bankofquebec.entity.Transaction;

@ManagedBean(name="gicManagedBean")
@SessionScoped
public class GICManagedBean {
	
	@ManagedProperty(value = "#{productManagedBean}")
	private ProductManagedBean productManagedBean;
	
	
	public List<Transaction> listLastMovements() {
		return productManagedBean.getSelectedProduct().getTransactions();
	}


	public GIC getGic() {
		return (GIC) productManagedBean.getSelectedProduct();
		
	}
	

	public ProductManagedBean getProductManagedBean() {
		return productManagedBean;
	}
	
	public String getExpirationDate(){
		GIC gic = (GIC) productManagedBean.getSelectedProduct();
		DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
		return df.format(gic.getInterestPaymentDate());
	}

	public double getInterests(){
		GIC gic = (GIC) productManagedBean.getSelectedProduct();
		return gic.calculateInterests();
	}

	public void setProductManagedBean(ProductManagedBean productManagedBean) {
		this.productManagedBean = productManagedBean;
	}
	
	


}
